package com.xt;

import java.awt.Point;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author v_guiqtong
 * @version 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MouseSelectData {

    private Point startPoint;

    private Point endPoint;

    private Point resultPoint;

    private int width;

    private int height;


    public void calculate() {
        width = endPoint.x>startPoint.x?endPoint.x-startPoint.x:startPoint.x-endPoint.x;
        height = endPoint.y>startPoint.y?endPoint.y-startPoint.y:startPoint.y-endPoint.y;
        resultPoint = new Point(Math.min(startPoint.x,endPoint.x),Math.min(startPoint.y,endPoint.y));
    }

    public Point getClickPoint() {
        int x = resultPoint.x+ (width/2);
        int y = resultPoint.y+ (height/2);
        return new Point(x,y);
    }

    public MouseSelectData  deepCopy(){
        MouseSelectData result = new MouseSelectData();
        result.setStartPoint(this.startPoint);
        result.setEndPoint(this.endPoint);
        result.setResultPoint(this.resultPoint);
        result.setWidth(this.width);
        result.setHeight(height);
        return result;
    }
}
